﻿#ifndef MBASEOBJECT_H
#define MBASEOBJECT_H

#include <QGraphicsObject>
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
#include <QPen>
#include <QDialog>

//当时就是因为忘记了public导致了函数成员的私有
class MBaseObject : public QGraphicsObject
{
public:

    enum OBJTYPE{ Base, GD_car, FS_car , CN_car};
    Q_ENUM(OBJTYPE)
    explicit MBaseObject(QGraphicsObject *parent = nullptr);
    ~MBaseObject() override;

    bool isGD_car() const                   { return objType() == MBaseObject::GD_car;}
    bool isFS_car() const                   { return objType() == MBaseObject::FS_car; }
    bool isCN_car() const                   { return objType() == MBaseObject::CN_car; }

    virtual MBaseObject::OBJTYPE objType() const { return MBaseObject::Base; }
    QString nameString() const;

    void drawSelectedRect(QPainter *painter); /* 画虚线框 */
    //静态变量的类外定义，直观不易被改变
    static QColor gBorderColor; /* 虚线框颜色 */
    //车牌号
    QGraphicsTextItem  *CarNumberItem;



    //提供对外修改的carNumber的接口
    void AddCarNumbertoCarnumbers(QStringList *carNumbers) { mcarNumbers = carNumbers;};  

    //获得车辆的IP
    QString* getCarIP()  {return &carIPstr;}




protected:
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
    //重写了移动函数
    QVariant itemChange(GraphicsItemChange change , const QVariant &value) override;



private:
    bool bSelected; //图元是否被选中
    QColor mObjectColor;//图元的默认颜色
    qreal mPenWidthF;//画图元的线宽
    QPointF offset;//item与其最近左上角坐标的偏移量
    QPointF computeTopLeftGridPoint(const QPointF &pointP); //用于捕获到pointP最近的左上角网格点
    QStringList *mcarNumbers;
    QString carIPstr;
};

#endif // MBASEOBJECT_H
